import { ref, onMounted } from "vue";
import { listUser } from "../api/system/user";

export function useYw() {
  const ywList = ref<any[]>([]);
  const loading = ref(false);
  const error = ref<string | null>(null);

  const fetchYwList = async () => {
    loading.value = true;
    error.value = null;
    try {
      const res = await listUser({
        pageNum: 1,
        pageSize: 100,
      });
      ywList.value = res.rows || [];
    } catch (e: any) {
      error.value = e.message || "获取业务员列表失败";
    } finally {
      loading.value = false;
    }
  };

  onMounted(fetchYwList);

  return {
    ywList,
    loading,
    error,
    fetchYwList,
  };
}
